package com.su.lesson04;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class ImageIconDemo extends JFrame {
    public ImageIconDemo() {
        //获取图片的地址
        URL url = ImageIconDemo.class.getResource("tx.png");
        ImageIcon imageIcon = new ImageIcon(url);

        JLabel label = new JLabel();
        label.setIcon(imageIcon);
        label.setHorizontalTextPosition(SwingConstants.CENTER);

        //getContentPane    获的窗体的内部窗格

        Container container = getContentPane();
        container.add(label);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new ImageIconDemo();
    }
}
